<template>
	<cl-drawer
		ref="drawer"
		:props="{
			title: '行为配置',
			size: '40%',
			appendToBody: true
		}"
		show-confirm
		confirm-text="提交"
		@close="reset"
		@confirm="submit"
		:saving="saving"
	>
		<el-form ref="form" label-position="top" :model="form" :rules="rules" :disabled="saving">
			<el-card shadow="never">
				<el-row :gutter="20">
					<el-col :span="12">
						<el-form-item label="日常总配" prop="ad_copy_total">
							<el-input
								v-model="form.ad_copy_total"
								@blur="form.ad_copy_total = $event.target.value"
								placeholder="请输入日常总配"
								oninput="value=value.replace(/[^\d^\.]/g,'')"
							/>
						</el-form-item>
					</el-col>
					<el-col :span="12">
						<el-form-item label="轮循频率" prop="ad_copy_one">
							<el-input
								v-model="form.ad_copy_one"
								@blur="form.ad_copy_one = $event.target.value"
								placeholder="请输入轮循频率"
								oninput="value=value.replace(/[^\d^\.]/g,'')"
							/>
						</el-form-item>
					</el-col>
				</el-row>
			</el-card>
		</el-form>
	</cl-drawer>
</template>
<script>
export default {
	data() {
		return {
			form: {
				biz_id: "",
				user_id: "",
				ad_copy_total: "",
				ad_copy_one: ""
		
			},
			rules: {
				ad_copy_total: [{ required: true, message: "请填写日常总配" }],
				ad_copy_one: [{ required: true, message: "请填写轮循频率" }]
			},
			saving: false
		};
	},
	methods: {
		open(data) {
			this.$refs.drawer.create();
			this.form = {
				biz_id: data.biz_id,
				user_id: data.user_id,
				ad_copy_total: data.user_ad_copy_total,
				ad_copy_one: data.user_ad_copy_one
			};
		},
		close() {
			this.$refs.drawer.close();
		},
		reset() {
			this.saving = false;
			this.$refs.form.resetFields();
		},
		submit() {
			this.$refs.form.validate(async (valid, errors) => {
				this.showFormErr(errors);
				if (!valid) return;
				await this.$service.ad.cusCopy(this.form).done(() => {
					this.saving = false;
				});
				this.$message.success("操作成功");
				this.$emit("confirm");
				this.reset();
				this.close();
			});
		}
	}
};
</script>
